/**
 * 
 */
package data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 * @author grupo22
 *
 */
public class JDBCPeriodDAO implements IPeriodDAO{
	public void updatePeriod(boolean b){
		Connection con = ConnectionManager.getInstance().checkOut();
		PreparedStatement stmt = null;
		try{
			String sql = "UPDATE Period SET votePeriod=?";
			stmt = con.prepareStatement(sql);
			stmt.setBoolean(1, b);
			
			stmt.executeUpdate();
		} catch (SQLException e) {
            System.out.println("Message: Fallo en updateProduct " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
        	ConnectionManager.getInstance().checkIn(con);
        	try {
        		if (stmt != null)
        			stmt.close();
            } catch (SQLException e) {}
        }
	}
	
	public boolean select(){
		Connection con = ConnectionManager.getInstance().checkOut();
		boolean votePeriod = false;
		PreparedStatement stmt = null;
		String sql = "SELECT * FROM Period";
		try{
			stmt = con.prepareStatement(sql);
			ResultSet rs = null;
			rs = stmt.executeQuery();			
			rs.next();
			votePeriod = rs.getBoolean("votePeriod");

		} catch (SQLException e) {
            System.out.println("Message: Fallo en updateProduct " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
        	ConnectionManager.getInstance().checkIn(con);
        	try {
        		if (stmt != null)
        			stmt.close();
            } catch (SQLException e) {}
        }
		return votePeriod;
	}

}
